import NormalLevelBase from "../../Game/Base/LevelBase";
import { GAME_EVENT, PAGE } from "../../Game/Enum";
import { IInGamePagePrams, ILosePagePrams, INormalLevelStruct } from "../../Game/Interface";
import mainRoot from "../../Game/MainRoot";
import goldMinerInGamePage from "../../Game/Page/goldMinerIngamePage";
import O1HD, { managers } from "../../engines/gameEngine";
import { CsvFileKind } from "../../engines/libs/CsvFileKind";
import data_control from "../../engines/libs/data_control";
import physics_tool from "../../engines/libs/physics_tool";
import CsvDataManage from "../../engines/managers/CsvDataManage";
import level_goldMiner_goodsBase from "./base/level_goldMiner_goodsBase";
import { goldMinerTag, hookState, propType } from "./const/goldMinerConst";
import level_goldMiner_shopItem from "./other/Level_goldMiner_shopItem";
import level_goldMiner_landmark from "./other/level_goldMiner_landmark";
import level_goldMinerShopPage from "./page/level_goldMinerShopPage";

const {ccclass, property} = cc._decorator;

@ccclass
export default class level_goldMiner extends NormalLevelBase {

    @property({type:cc.Node,tooltip:"钩子节点"})
    hookNode:cc.Node = null;

    @property({type:cc.Node,tooltip:"钩子动画节点"})
    hookAniNode:cc.Node = null;

    @property({type:cc.Node,tooltip:"点击节点"})
    touchNode:cc.Node = null;

    @property({type:cc.Node,tooltip:"游戏区域"})
    gameArea:cc.Node = null;

    @property({type:cc.Node,tooltip:"地图区域"})
    mapArea:cc.Node = null;

    @property({type:cc.Node,tooltip:"角色节点"})
    roleNode:cc.Node = null;

    @property({type:cc.Node,tooltip:"角色汗珠"})
    roleKhan:cc.Node = null;

    @property({type:cc.Animation,tooltip:"绳子抖动动画"})
    ropeShakeAni:cc.Animation = null;

    @property({type:cc.Node,tooltip:"商人节点"})
    merchant:cc.Node = null;

    @property({type:cc.Node,tooltip:"商人对话节点"})
    merchantChatNode:cc.Node = null;

    @property({type:cc.Label,tooltip:"商人对话文本"})
    lbChat:cc.Label = null;

    @property({type:cc.Label,tooltip:"钱文本"})
    lbMoney:cc.Label = null;

    @property({type:cc.Node,tooltip:"显示文本"})
    lbShow:cc.Node = null;

    cameraNode:cc.Node = null;

    @property({type:cc.Node,tooltip:"摄像机目标节点"})
    cameraTargetNode:cc.Node = null;

    @property({type:cc.Node,tooltip:"炸弹layout"})
    boomLayout:cc.Node = null;

    @property({type:cc.Prefab,tooltip:"炸弹节点"})
    boomItem:cc.Prefab = null;

    /** 0 静止 1左摆 2右摆 3往前伸 4 往后拉*/
    hookState:hookState = hookState.idle;

    /**钩子是否旋转 */
    hookRotationFlag:boolean = false;

    /**钩子旋转速度 */
    hookAngularVelocity:number = 0;

    /**钩子最大旋转角度 */
    hookMaxAngle:number = 75;

    /**钩子减速角度 */
    hookRetardAngle:number = 50;

    /**钩子最大速度 */
    hookMaxAngularVelocity:number = 2.25 * 60;

    /**钩子最小速度 */
    hookMinAngularVelocity:number = 0.1 * 60;

    /**当前勾中的物品 */
    curGoods:cc.Node = null;

    /**游戏是否暂停 */
    gamePauseFlag:boolean = true;

    /**钩子伸出速度 */
    hookStretchSpeed:number = 500;

    /**钩子勾空拉回速度 */
    hookNullSpeed:number = 1000;

    /**游戏进度 */
    gameStep:number = 0;

    /**当前的钱 */
    curMoney:number = 0;

    /**目标需要的钱 */
    targetMoney:number = 0;

    /**当前阶段倒计时 */
    curCountDown:number = 0;

    /**切换状态之前的最后一个旋转状态 */
    lastHookState:hookState = hookState.idle;

    targetMoneyAry:number[] = [];

    coutDownAry:number[] = [];

    levelData:any = null;

    inGamePage:goldMinerInGamePage = null;

    canTouch:boolean = false;

    hasClean:boolean = false;

    ropeInitHeight:number = 0;

    async Init(info: INormalLevelStruct): Promise<void> {
        this.levelInfo = info;
        this.m_mode = info.mode;
        this.tips = info.tips;
        // console.warn("关卡初始化", this.levelInfo);
        let inGamePrams: IInGamePagePrams = {
            mode: this.m_mode,
            levelInfo:this.levelInfo,
            title: info.title,
            tips: info.tips,
            hideTitle: info.hideTitle
        }
        O1HD.getManagers().soundMgr.loadSoundBundle("goldMinerSound");
        O1HD.on(GAME_EVENT.ON_BTN_TIPS, this.OnTips.bind(this));
        this.levelData = O1HD.getManagers().csvDataManager.getCsvDataItem(CsvFileKind.CsvFile.goldMinerLevel,this.levelInfo.level);
        this.targetMoneyAry = this.levelData["turn_target"].split("|").map(v=>Number(v));
        this.coutDownAry = this.levelData["turn_time"].split("|").map(v=>Number(v));
        let page = await mainRoot.UISystem.OpenPage(PAGE.GOLD_MINER_INGAME_PAGE,inGamePrams);
        this.hookStretchSpeed = Number(this.levelData["hook_stretch_speed"]);
        this.hookNullSpeed = Number(this.levelData["hook_null_speed"]);
        this.inGamePage = page as goldMinerInGamePage;
        this.inGamePage.bindLevel(this);
        this.ropeInitHeight = this.hookNode.getChildByName("rope").height;
        this.refrenshBoomLayout();
        await this.loadGame();
        this.touchNodeAddEvent();
        this.hookState = hookState.left;
        this.lastHookState = hookState.left;
        this.gameResume();
        physics_tool.openCollision();
    }

    async start(){
        this.cameraNode = O1HD.Canvas().getChildByName("Main Camera");
        O1HD.on("refrenshBoom",this.refrenshBoomLayout,this);
    }

    startHook(){
        this.hookRotationFlag = true;
    }

    stopHook(){
        this.hookRotationFlag = false;
    }

    hookAni(){
        let needTime:number = 1;
        cc.tween(this.hookNode).to(needTime,{angle:-75},{easing:cc.easing.backOut}).to(needTime,{angle:0},{easing:cc.easing.backIn}).start();
    }

    async loadGame(){
        this.gameArea.destroyAllChildren();
        let needCounts:number = this.mapArea.children[this.gameStep].childrenCount;
        this.targetMoney = this.targetMoneyAry[this.gameStep];
        this.curCountDown = this.coutDownAry[this.gameStep];
        let curCount:number = 0;
        this.inGamePage.refrenshTime();
        this.refrenshCurMoney();
        this.inGamePage.refrenshStep();
        await new Promise<void>(resolve=>{
            if(needCounts == 0){
                resolve();
                return;
            }
            this.mapArea.children[this.gameStep].children.forEach((n:cc.Node)=>{
                let ns = n.getComponent(level_goldMiner_landmark);
                let nid:string = ns.getObjId();
                let data = O1HD.getManagers().csvDataManager.getCsvDataItem(CsvFileKind.CsvFile.goldMinerHoookGooods,nid);
                let prefabPath:string = data["prefab_path"];
                mainRoot.LevelSystem.getOneTypeBundle(this.getLevelInfo().levelType).load(`level_abb_goldMiner/${prefabPath}`,cc.Prefab,(err:Error,prefab:cc.Prefab)=>{
                    if(err){
                        console.log(err,"加载物品失败");
                        return;
                    }
                    let node:cc.Node = cc.instantiate(prefab);
                    let ns = node.getComponent(level_goldMiner_goodsBase);
                    ns.bindData(data);
                    let pos = this.gameArea.convertToNodeSpaceAR(n.convertToWorldSpaceAR(cc.v2()));
                    node.parent = this.gameArea;
                    node.setPosition(pos);
                    curCount ++;
                    if(curCount == needCounts){
                        resolve();
                    }
                });
            });
        });
        await this.inGamePage.showTargetNode(this.targetMoney);
        this.refrenshCurMoney();
        this.canTouch = true;
        this.schedule(this.subCountDown,1);
    }

    update(dt: number): void {
        if(this.gamePauseFlag){
            return;
        }
        let subAngle:number = this.hookMaxAngularVelocity * dt;
        let angle = this.hookMaxAngle - this.hookRetardAngle;
        let ratio:number = (Math.abs(this.hookNode.angle) - Math.abs(this.hookRetardAngle)) / angle;
        let addition:number = O1HD.getManagers().goldMinerManager.getAdditionByLevel();
        switch(this.hookState){
            case hookState.idle:{

                break;
            }
            case hookState.left:{
                if(this.hookNode.angle <= - this.hookRetardAngle){
                    subAngle = (this.hookMaxAngularVelocity * dt) - (ratio * this.hookMaxAngularVelocity) * dt;
                    subAngle = Math.max(subAngle,this.hookMinAngularVelocity * dt);
                }
                this.hookNode.angle -= subAngle;
                if(this.hookNode.angle <= -this.hookMaxAngle){
                    this.hookState = hookState.right;
                    this.lastHookState = hookState.right;
                }
                break;
            }
            case hookState.right:{
                if(this.hookNode.angle >= this.hookRetardAngle){
                    subAngle = (this.hookMaxAngularVelocity * dt) - (ratio * this.hookMaxAngularVelocity * dt);
                    subAngle = Math.max(subAngle,this.hookMinAngularVelocity * dt);
                }
                this.hookNode.angle += subAngle;
                // this.hookNode.angle -= this.hookMaxAngularVelocity;
                if(this.hookNode.angle >= this.hookMaxAngle){
                    this.hookState = hookState.left;
                    this.lastHookState = hookState.left;
                }
                break;
            }
            case hookState.stretch:{
                    let rope:cc.Node = this.hookNode.getChildByName("rope");
                    let hook:cc.Node = rope.getChildByName("hook");
                    rope.height += (this.hookStretchSpeed + this.hookStretchSpeed * addition) * dt;
                    if(!hook.getBoundingBoxToWorld().intersects(this.touchNode.getBoundingBoxToWorld())){
                        this.hookState = hookState.pullBack;
                    }
                break;
            }
            case hookState.pullBack:{
                    let rope = this.hookNode.getChildByName("rope");
                    let speed:number = this.hookNullSpeed;
                    if(this.curGoods && this.curGoods.isValid){
                        speed = Number(this.curGoods.getComponent(level_goldMiner_goodsBase).data["return_speed"]) + (Number(this.curGoods.getComponent(level_goldMiner_goodsBase).data["return_speed"]) * addition);
                    }else{
                        speed = this.hookNullSpeed + (this.hookNullSpeed * addition);
                    }
                    let curHeight = speed * dt;
                    if(rope.height - curHeight < this.ropeInitHeight){
                        curHeight = rope.height - this.ropeInitHeight;
                    }
                    rope.height -= curHeight;
                    if(rope.height <= this.ropeInitHeight){
                        this.ropeShakeAni.node.active = false;
                        this.hookState = this.lastHookState;
                        this.peopleStopKhan();
                        this.roleNode.getComponent(cc.Animation).play("idle");
                        this.hookAniNode.getComponent(cc.Animation).play("idle");
                        if(this.curCountDown <=0){
                            this.canTouch = false;
                        }
                        this.recycleObj().then(()=>{
                            if(this.curCountDown <=0){
                                this.checkGame();
                            }else if(this.gameArea.childrenCount <= 0){
                                this.checkGame();
                            }
                        });
                    }
                break;
            }
        }
    }

    async recycleObj(){
        if(this.curGoods){
            this.hasClean = true;
            return new Promise<void>(resolve=>{
                let node:cc.Node = this.curGoods;
                let pos:cc.Vec2 = this.node.convertToNodeSpaceAR(node.convertToWorldSpaceAR(cc.v2()));
                node.setParent(this.node);
                node.setPosition(pos);
                this.curGoods = null;
                let cs = node.getComponent(level_goldMiner_goodsBase);
                let cData = cs.data;
                let minMoney = Number(cData["min_price"]);
                let maxMoney = Number(cData["max_price"]);
                let realMoney:number = Math.floor(data_control.getRandNumberOfArrayTwo([minMoney,maxMoney]));
                let oneRealMoney:number = realMoney;
                let cType = cData["good_classification"];
                switch(cType){
                    case "2":{
                        realMoney = realMoney + realMoney * O1HD.getManagers().goldMinerManager.diamondPrice;
                        break;
                    }
                    case "4":{
                        realMoney = realMoney + realMoney * O1HD.getManagers().goldMinerManager.boxPrice;
                        break;
                    }
                    case "6":{
                        O1HD.getManagers().goldMinerManager.setData({hookLevel:1},true);
                        this.showSpeedUpgrade();
                        break;
                    }
                }
                realMoney = Math.floor(realMoney + oneRealMoney * O1HD.getManagers().goldMinerManager.allPrice);
                let targetPos:cc.Vec2 = this.node.convertToNodeSpaceAR(this.roleNode.convertToWorldSpaceAR(cc.v2()));
                // let converPos:cc.Vec2 = this.gameArea.convertToNodeSpaceAR(node.convertToWorldSpaceAR(cc.v2()));
                // node.setParent(this.gameArea);
                // node.setPosition(converPos);
                // console.log(this.gameArea.getPosition(),">>>>>>>>>>",targetPos,"targetPos")
                //@ts-ignore
                cc.tween(node).to(0.2,{position:targetPos}).to(0.5,{opacity:0}).call(()=>{
                    if(realMoney > 0){
                        this.addMoney(realMoney);
                    }
                    this.hasClean = false;
                    resolve();
                    node.destroy();
                    node.removeFromParent();
                }).start();
                // let tween = cc.tween(node).delay(0.3).to(0,{opacity:0}).delay(0.3).to(0,{opacity:255});
                // cc.tween(node).repeat(2,tween).call(()=>{
                    
                // }).start();
            });
        }
    }

    touchNodeAddEvent(){
        this.touchNode.on("touchend",this.onTouchEndNode,this);
    }

    onTouchEndNode(e:cc.Event.EventTouch){
        if(this.gamePauseFlag){
            return;
        }
        if(!this.canTouch){
            return;
        }
        if(this.hookState == hookState.left || this.hookState == hookState.right){
            //切换成前伸 钩子飞出
            this.roleNode.getComponent(cc.Animation).play("ani");
            this.hookState = hookState.stretch;
        }else if(this.hookState == hookState.pullBack){
            // 回收状态点击钩子 如果有炸弹道具则直接使用炸弹道具 如果没有则无需操作 等待拉伸结束即可
            if(O1HD.getManagers().goldMinerManager.boomNum > 0 && this.curGoods){
                O1HD.getManagers().goldMinerManager.useBoom();
                let node:cc.Node = this.curGoods;
                let pos = this.gameArea.convertToNodeSpaceAR(node.convertToWorldSpaceAR(cc.v2()));
                node.parent = this.gameArea;
                node.setPosition(pos);
                let boomItem:cc.Node = this.boomLayout.children[O1HD.getManagers().goldMinerManager.boomNum];
                let boomPos:cc.Vec2 = this.gameArea.convertToNodeSpaceAR(boomItem.convertToWorldSpaceAR(cc.v2()));
                boomItem.setParent(this.gameArea);
                boomItem.setPosition(boomPos);
                this.refrenshBoomLayout();
                let ani:cc.Animation = boomItem.getComponent(cc.Animation);
                ani.play("Throw");
                //@ts-ignore
                cc.tween(boomItem).to(0.2,{position:pos,angle:360}).call(()=>{
                    O1HD.getManagers().soundMgr.playSound("goldMinerSound/boom");
                    ani.play("Boom");
                    ani.on('finished',()=>{
                        boomItem.destroy();
                        boomItem.removeFromParent();
                    },this);
                    node.destroy();
                    node.removeFromParent();
                    // ani.on('')
                }).start();
                // this.curGoods.destroy();
                // this.curGoods.removeFromParent();
                this.curGoods = null;
            }
        }
    }

    /**
     * 碰撞
     * @param oneColider 
     * @param twoColider
     */
    onColision(oneColider:cc.Collider,twoColider:cc.Collider){
        let os = oneColider.node.getComponent(level_goldMiner_goodsBase);
        if(oneColider.tag == goldMinerTag.goods && twoColider.tag == goldMinerTag.hoook && !this.curGoods && !os.pullBackFlag && this.hookState == hookState.stretch){
            // 钩子碰到了物品
            O1HD.getManagers().soundMgr.playSound("goldMinerSound/sound");
            this.curGoods = oneColider.node;
            let objLayout:cc.Node = this.hookNode.getChildByName("rope").getChildByName("hook").getChildByName("objLayout");
            this.ropeShakeAni.node.active = true;
            this.ropeShakeAni.play();
            let cs = this.curGoods.getComponent(level_goldMiner_goodsBase);
            cs.toPullBack();
            let chatType:string = cs.data["chat_type"];
            let objId = cs.data["objId"];
            if(Math.random() < Number(this.levelData["obj_chat_pro"])){
                this.showOneChat(chatType,objId);
            }
            this.curGoods.setParent(objLayout);
            this.curGoods.setPosition(0,-10 - this.curGoods.height / 2);
            this.hookState = hookState.pullBack;
            this.hookAniNode.getComponent(cc.Animation).play("ani");
            this.peopleStartKhan();
        }
    }

    /**游戏暂停 */
    gamePause(){
        this.gamePauseFlag = true;
    }

    /**游戏继续 */
    gameResume(){
        this.gamePauseFlag = false;
    }

    addMoney(money:number){
        this.curMoney += money;
        let node:cc.Node = cc.instantiate(this.lbShow);
        let label:cc.Label = node.getComponent(cc.Label);
        label.string = `+${money}`;
        let pos:cc.Vec2 = this.node.convertToNodeSpaceAR(this.roleNode.convertToWorldSpaceAR(cc.v2()));
        pos.y += 120;
        node.setParent(this.node);
        node.setPosition(pos);
        node.scale = 0.5;
        cc.tween(node).by(0.2,{y:50,scale:0.5}).delay(1).call(()=>{
            node.destroy();
            node.removeFromParent();
        }).start();
        this.refrenshCurMoney();
    }

    refrenshCurMoney(){
        this.lbMoney.string = data_control.getNumberFormat(this.curMoney) + "/" + data_control.getNumberFormat(this.targetMoney);
    }

    async subCountDown(){
        if(this.gamePauseFlag){
            return;
        }
        this.curCountDown --;
        this.curCountDown = Math.max(0,this.curCountDown);
        this.inGamePage.refrenshTime();
        if(this.curCountDown <= 0){
            // 判断是否达到了目标 如果没达到则判断失败
            this.checkGame();
        }
    }

    checkGame(){
        console.log("checkGame");
        if(this.hookState != hookState.pullBack && this.hookState != hookState.stretch && !this.hasClean){
            if(this.curMoney >= this.targetMoney){
                this.gameStep ++;
                if(this.gameStep >= this.targetMoneyAry.length){
                    this.Win(2);
                    this.unschedule(this.subCountDown);
                }else{
                    this.stepEnd();
                    this.unschedule(this.subCountDown);
                }
            }else{
                this.Lose(2);
                this.unschedule(this.subCountDown);
            }
        }
    }

    async stepEnd(){
        this.canTouch = false;
        O1HD.getManagers().soundMgr.playSound("goldMinerSound/transition");
        await this.cameraAni(true);
        await this.showOneChat("3",null,3);
        O1HD.getManagers().goldMinerManager.resetProp();
        this.refrenshBoomLayout();
        O1HD.getManagers().soundMgr.playSound("goldMinerSound/store");
        await this.showShopPage();
        await this.loadGame();
        await this.cameraAni(false);
    }

    async showShopPage(){
        return new Promise<void>(async resolve=>{
            let page = await mainRoot.UISystem.OpenPage(PAGE.LEVEL_GOLD_MINER_SHOPPAGE);
            let p = page as level_goldMinerShopPage;
            p.bindLevel(this,resolve);
        });
    }

    async cameraAni(endFlag:boolean){
        return new Promise<void>(resolve=>{
            if(endFlag){
                //@ts-ignore
                cc.tween(this.cameraNode).to(1,{position:this.cameraTargetNode.getPosition()}).start();
                cc.tween(this.cameraNode.getComponent(cc.Camera)).to(1,{zoomRatio:1.5}).call(resolve).start();
            }else{
                cc.tween(this.cameraNode).to(1,{position:cc.v3(0,0,0)}).start();
                cc.tween(this.cameraNode.getComponent(cc.Camera)).to(1,{zoomRatio:1}).call(resolve).start();
            }
        });
    }

    /**
     * 商人展示某一种类型的对话
     * @param type 类型 
     * @param objId 物品id
     */
    showOneChat(type:string,objId:string,autoHideTime:number = 5){
        return new Promise<void>(resolve=>{
            this.merchant.getComponent(cc.Animation).play("ani");
            let chats = this.getOneTypeChats(type,objId);
            let chat:string = data_control.getRandItemOfArray(chats);
            this.lbChat.string = chat["chat_desc"];
            cc.Tween.stopAllByTarget(this.merchantChatNode);
            cc.tween(this.merchantChatNode).to(0.2,{scale:1},{easing:cc.easing.backOut}).delay(autoHideTime).call(()=>{
                this.hideOneChat();
                this.merchant.getComponent(cc.Animation).play("idle");
                resolve();
            }).start();
        });
    }

    hideOneChat(){
        cc.tween(this.merchantChatNode).to(0.2,{scale:0},{easing:cc.easing.backIn}).start();
    }

    getOneTypeChats(type:string,objId:string){
        let allChat:string[] = O1HD.getManagers().csvDataManager.getCsvIds(CsvFileKind.CsvFile.goldMinerChats);
        let chatAry:string[] = [];
        let commonAry:string[] = [];
        for(let id of allChat){
            let chat = O1HD.getManagers().csvDataManager.getCsvDataItem(CsvFileKind.CsvFile.goldMinerChats,id);
            if(chat["type"] == type){
                chatAry.push(chat);
            }
            if(chat["objId"] == objId && chat["type"] == type){
                commonAry.push(chat);
            }
        }
        if(commonAry.length > 0){
            return commonAry;
        }else {
            return chatAry;
        }
    }

    targetLbAni(){
        let tween = cc.tween(this.lbMoney.node).delay(0.1).to(0,{color:cc.Color.RED}).delay(0.1).to(0,{color:cc.color(57,17,2)});
        cc.tween(this.lbMoney.node).repeat(3,tween).start();
        
    }

    refrenshBoomLayout(){
        let targetCount:number = O1HD.getManagers().goldMinerManager.boomNum;
        let nowCount:number = this.boomLayout.childrenCount;
        let needCount:number = targetCount - nowCount;
        if(needCount > 0){
            for(let i =0;i<needCount;i++){
                let node:cc.Node = cc.instantiate(this.boomItem);
                node.parent = this.boomLayout;
                let ani:cc.Animation = node.getComponent(cc.Animation);
                ani.play("Idle");
            }
        }
    }

    peopleStartKhan(){
        this.roleKhan.y = 115;
        this.roleKhan.scale = 0.5;
        this.roleKhan.opacity = 0;
        let tween = cc.tween(this.roleKhan).call(()=>{
            this.roleKhan.opacity = 255
        }).to(0.3,{y:95,scale:1}).delay(0.2).call(()=>{
            this.roleKhan.opacity = 0;
            this.roleKhan.scale = 0.5;
            this.roleKhan.y = 115;
        }).delay(1);
        cc.tween(this.roleKhan).repeatForever(tween).start();
    }

    peopleStopKhan(){
        this.roleKhan.y = 115;
        this.roleKhan.scale = 0.5;
        this.roleKhan.opacity = 0;
        cc.Tween.stopAllByTarget(this.roleKhan);
    }

    Lose(time?: number): void {
        if (this.hadEnd) { return; }
        this.hadEnd = true;
        let delayTime: number = 2;
        if (time) {
            delayTime = time;
        }
        this.scheduleOnce(() => {
            managers().soundMgr.playSound('mainSound/inLevel');
            let losePrams: ILosePagePrams = {
                mode: this.m_mode,
                loseText: this.levelInfo.loseText,
                tips: this.levelInfo.tips,
                index: this.levelInfo.level
            };
            mainRoot.UISystem.OpenPage(PAGE.LOSEPAGE, losePrams);
        }, delayTime);
    }

    showSpeedUpgrade(){
        let node:cc.Node = cc.instantiate(this.lbShow);
        let label:cc.Label = node.getComponent(cc.Label);
        label.string = `速度提升`;
        node.color = cc.color(48,255,194);
        let pos:cc.Vec2 = this.node.convertToNodeSpaceAR(this.roleNode.convertToWorldSpaceAR(cc.v2()));
        pos.y += 120;
        node.setParent(this.node);
        node.setPosition(pos);
        node.scale = 0.5;
        cc.tween(node).by(0.2,{y:50,scale:0.5}).delay(1).call(()=>{
            node.destroy();
            node.removeFromParent();
        }).start();
        this.refrenshCurMoney();
    }

}
